#ifndef SEARCHLISTWIDGET_H
#define SEARCHLISTWIDGET_H

#include <QWidget>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QSet>
#include "songitemwidget.h"

namespace Ui {
class SearchListWidget;
}

class SearchListWidget : public QWidget
{
    Q_OBJECT

public:
    explicit SearchListWidget(QWidget *parent = nullptr);
    ~SearchListWidget();
    bool eventFilter(QObject *watched, QEvent *event);
    void addSongItem(SongItemWidget *songItem);
    void search(const QString& searchText);
    void pageSearch(const QString& searchText, int limit, int offset);
private:
    void clearOldDatas();
    void setSearchText(const QString& searchText);
    void updateSearchText();
    void getPicUrlByAlbumId(int index, qint64 album_id);
    void getSongUrl(SongItemWidget* songItem, qint64 songId);

    void on_reply_finished(QNetworkReply* reply);
    void on_imageReply_finished(int index, QNetworkReply* reply);
    void on_songItem_played(int index, bool play);
private slots:
    void on_pushButton_playAll_clicked();

    void on_pushButton_favoriteAll_clicked();

signals:
    void played(SongItem songItem, bool play);
    void playAll(const QVector<QUrl>& songs);

private:
    QString _old_searchText;
    QVector<SongItemWidget*> _songItems;
    QVector<qint64> _id;
    QNetworkAccessManager* _manager;
    QSet<QNetworkReply*> _replys;
    Ui::SearchListWidget *ui;
};

#endif // SEARCHLISTWIDGET_H
